package com.wdzl.model;

import com.wdzl.util.ImageUtil;
import com.wdzl.util.ShadowUtil;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

/**
 * @Author: zhang
 *
 */
public class Card extends JLabel implements Comparable<Card> {
    private Image img;
    private ImageIcon imageIcon;
    private String id;          // 编号，area-i-j-
    private int areaType;       // 区域类型
    private boolean isSelected; // 是否被点中放入消除框
    private boolean isDeleted;  // 是否已经消除
    private boolean isGray;     // 是否灰色
    private int posZ;           // 垂直方向位置，塔形层数

    public Card(ImageIcon imageIcon){
//        super(imageIcon);
        this.imageIcon = imageIcon;
        this.img = imageIcon.getImage();
    }

    public Image getImg() {
        return img;
    }

    public void setImg(Image img) {
        this.img = img;
    }

    public ImageIcon getImageIcon() {
        return imageIcon;
    }

    public void setImageIcon(ImageIcon imageIcon) {
        this.imageIcon = imageIcon;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }

    public boolean isDeleted() {
        return isDeleted;
    }

    public void setDeleted(boolean deleted) {
        isDeleted = deleted;
    }

    public boolean isGray() {
        return isGray;
    }

    public void setGray(boolean gray) {
        isGray = gray;
    }

    public int getAreaType() {
        return areaType;
    }

    public void setAreaType(int areaType) {
        this.areaType = areaType;
    }

    public int getPosZ() {
        return posZ;
    }

    public void setPosZ(int posZ) {
        this.posZ = posZ;
    }
    //    public Card(){}

//    @Override
    public void paint(Graphics g) {
//        g.fillRect(0,0,getWidth(),getHeight());
//        System.out.println(getX()+"====paint===="+getY());
        g.drawImage(img,0,0,null);
        //绘制罩影
        drawShadow(g);
    }

    /**
     * 绘制照影
     */
    public void drawShadow(Graphics g){
        if(!isGray){
            return;
        }
        ShadowUtil.drawShadow(g,0,0,imageIcon.getIconWidth(),imageIcon.getIconHeight());
    }

    @Override
    public int compareTo(Card o) {
        //相同的图案卡 有相同的名字
        return this.getName().compareTo(o.getName());
    }
}
